import Taro from '@tarojs/taro';
import { getPlatform } from '@UTILS/common'
const { isRN } = getPlatform()

const getStorageSync = async key => {
  if (!isRN) {
    return Taro.getStorageSync(key)
  }
  try {
    const result = await Taro.getStorage({ key })
    return result?.data
  } catch (err) {
    return ''
  }
}
const removeStorageSync = async key => {
  if (!isRN) {
    return Taro.removeStorageSync(key)
  }
  try {
    const result = await Taro.removeStorage(key)
    return result?.data
  } catch (err) {
    return ''
  }
}

if (isRN) {
  Taro.getStorageSync = getStorageSync;
  Taro.removeStorageSync = removeStorageSync;
}

export { getStorageSync, removeStorageSync }
